<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>01逛水果店</title>
    <style>
      #app{
        text-align: center;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <p>欢迎光临水果店</p>
      <table border="1" width="500px" height="30px">
        <tr>
            <td>苹果 10￥/斤. 折扣 <8折></8></td>
        </tr>
        <tr>
            <td>请输入你要购买的斤数
                <input type="number" v-model="weight" /></td>
        </tr>
        <tr>
            <td><button @click="checkout">结账买单</button></td>
        </tr>
        <tr>
            <td>结账单: 总价: {{ total }} ￥ 折后价: {{ discountedPrice }} ￥ 省了: {{ savedPrice }} ￥</td>
        </tr>
      </table>
    </div>
    <script src="../vue.js"></script>
    <script>
      const app = new Vue({
  el: '#app',
  data: {
    weight: 0,
    total:0,
    discountedPrice:0,
    savedPrice:0
    },
  methods: {
    checkout() {
      this.total = 10 * this.weight
      this.discountedPrice = this.total * 0.8
      this.savedPrice = this.total-this.discountedPrice
    }
  }
});
    </script>
  </body>
</html>
